package jspx.example.test;

import com.github.jspxnet.sober.annotation.Column;
import com.github.jspxnet.sober.annotation.Id;
import com.github.jspxnet.sober.annotation.Table;
import com.github.jspxnet.sober.model.container.PropertyContainer;
import com.github.jspxnet.utils.HtmlUtil;
import com.github.jspxnet.utils.StringUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;

@EqualsAndHashCode(callSuper = true)
@Data
@Table(name = "jcms_friend_D", caption = "测试动态扩展类")
public class FriendLinkD extends PropertyContainer {
    @Id
    @Column(caption = "ID", notNull = true)
    private long id = 0;

    @Column(caption = "标题", dataType = "isLengthBetween(1,80)", length = 80, notNull = true)
    private String title = StringUtil.empty;

    @Column(caption = "logoURL", dataType = "isLengthBetween(1,200)", length = 200, notNull = true)
    private String logoUrl = StringUtil.empty;

    @Column(caption = "URL", dataType = "isLengthBetween(1,200)", length = 200, notNull = true)
    private String url = StringUtil.empty;

    @Column(caption = "说明", dataType = "isLengthBetween(1,250)", length = 250, notNull = true)
    private String synopsis = StringUtil.empty;

    @Column(caption = "分组")
    private int groupId = 0;

    @Column(caption = "排序")
    private int sortType = 0;

    @Column(caption = "排序日期", notNull = true)
    private Date sortDate = new Date();

    @Column(caption = "最后操作时间", notNull = true)
    private Date lastDate = new Date();

    @Column(caption = "命名空间", length = 50, dataType = "isLengthBetween(1,50)")
    private String namespace = StringUtil.empty;

    private FriendLinkD friendLink;

    public String getLogoImage() {
        if (logoUrl == null || "".equals(logoUrl) || "null".equalsIgnoreCase(logoUrl)) {
            return StringUtil.empty;
        }
        return "<img src=" + logoUrl + " border=0/>";
    }

    public String getFriendLink() {
        StringBuilder sb = new StringBuilder();
        sb.append("<a href=\"").append(url).append("\" target=\"_blank\" title=\"").append(HtmlUtil.deleteHtml(synopsis, 150, ".")).append("\">");
        if (!StringUtil.isNull(logoUrl)) {
            sb.append(getLogoImage());
        } else {
            sb.append(title);
        }
        sb.append("</a>");
        return sb.toString();
    }

}